package gazzera.node.core.plugins.shareplugin;

import static com.sleepycat.persist.model.DeleteAction.*;
import static com.sleepycat.persist.model.Relationship.*;
import gazzera.node.core.plugins.download.*;
import gazzera.utils.*;

import com.sleepycat.persist.model.*;

@Deprecated @Entity
public class FileDesc {

	@PrimaryKey
	public int id = 0;
	
	@SecondaryKey(relate=MANY_TO_ONE,relatedEntity=FileDesc.class,onRelatedEntityDelete=CASCADE)
	public int parentId = 0;
	
	@SecondaryKey(relate=MANY_TO_ONE)
	public int shareId = 0;

	public boolean directory = false;
	public String filename = "";
	public long timestamp = 0;
	public long size = 0;
	public boolean hasSubdir = false;
	public String location = null;
	
	@SecondaryKey(relate=MANY_TO_ONE)
	public Hash hash = Hash.EMPTY;
	
	
	public int getChunkCount()
	{
		int mod = (int)(size % Download.CHUNK_SIZE);
		int num = (int)(size / Download.CHUNK_SIZE);
		if(mod>0) num++;
		return num;
	}
	
	public int getChunkSize(int chunkIdx)
	{
		int mod = (int)(size % Download.CHUNK_SIZE);
		int num = (int)(size / Download.CHUNK_SIZE);
		
		if(chunkIdx<num)
		{
			return Download.CHUNK_SIZE;
		}
		else
		{
			return mod;
		}
	}

}
